home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / util / rexx / savetime.lha / savetime.miami next >
Text File  |  1997-02-18  |  3KB  |  117 lines

  1. /*
  2.     $VER: savetime.miami 1.0 (18 Feb 1997)
  3.  
  4.     savetime.miami for Miami 1.1 or better
  5.     © Georges Heinesch <geohei@ibm.net>
  6.  
  7.     Saves the ntp updated system time to the battery-powered real-time
  8.     clock. Optionally creates a log file showing the difference between the
  9.     system time and ntp time.
  10.  
  11.     See savetime.readme for details.
  12. */
  13.  
  14.  
  15.  
  16.  
  17.  
  18. /*
  19.     Varibles
  20.  
  21.     'log'      - logging desired or not; 'true' or 'false'
  22.     'logfile'  - if 'log' variable is set to 'true', enter the filename here
  23.                  (including the path from PROGDIR:)
  24.     'secdelta' - fix value for correction purpose, depending on system speed
  25. */
  26.  
  27. log      = 'true'
  28. logfile  = 'Miami_Time.log'
  29. secdelta = 1
  30.  
  31.  
  32.  
  33.  
  34.  
  35. /* body */
  36.  
  37. options results
  38.  
  39. /* if log not desired, save ntp time and exit */
  40.  
  41. if log ~= 'true' then
  42.   do
  43.     address command 'C:SetClock SAVE'
  44.     exit
  45.   end
  46.  
  47. /* get ntp time */
  48.  
  49. address command 'C:Date >T:Date'
  50. if open( date,'T:Date',r ) then
  51.   do
  52.     datentp = readln( date )
  53.     call close( date )
  54.     address command 'C:Delete >T:Date'
  55.   end
  56. else
  57.   say 'Could not open "T:Date" !!!'
  58.  
  59. timentp = right( datentp,8 )
  60.  
  61. /* get old system time */
  62.  
  63. address command 'C:SetClock LOAD >T:Date'
  64. address command 'C:Date >T:Date'
  65. if open( date,'T:Date',r ) then
  66.   do
  67.     dateold = readln( date )
  68.     call close( date )
  69.     address command 'C:Delete >T:Date'
  70.   end
  71. else
  72.   say 'Could not open "T:Date" !!!'
  73.  
  74. timeold = right( dateold,8 )
  75.  
  76. /* save ntp time */
  77.  
  78. address command 'C:Date' timentp
  79. address command 'C:SetClock SAVE'
  80.  
  81. /* compare both times and log */
  82.  
  83. secntp = left( timentp,2 ) * 3600 + substr( timentp,4,2 ) *60 + right( timentp,2 )
  84. secold = left( timeold,2 ) * 3600 + substr( timeold,4,2 ) *60 + right( timeold,2 )
  85. secerror = secntp - secold - secdelta
  86. if ( secerror > 0 ) then timeerror = '+'
  87. if ( secerror < 0 ) then timeerror = '-'
  88. if ( secerror = 0 ) then timeerror = ' '
  89. secerror = abs( secerror )
  90. hh = right( '0' || trunc( secerror / 3600 ),2 )
  91. mm = right( '0' || trunc( ( secerror - hh * 3600 ) / 60 ),2 )
  92. ss = right( '0' || secerror - hh * 3600 - mm * 60,2 )
  93. timeerror = timeerror || hh || ':' || mm || ':' || ss
  94.  
  95. error = word( datentp,2,1 ) || '     ' || timeold || '  ' || timentp || '  ' || timeerror
  96.  
  97. if ~open( log,logfile,r ) then
  98.   do
  99.     call open( log,logfile,w ) then
  100.     writeln( log,'Date          old time  ntp time  error' )
  101.     writeln( log,'---------     --------  --------  ---------' )
  102.   end
  103. call close( log )
  104.  
  105. if open( log,logfile,a ) then
  106.   do
  107.     writeln( log,error )
  108.     call close( date )
  109.     address command 'C:Delete >T:Date'
  110.   end
  111. else
  112.   say 'Could not open "' || logfile || '" !!!'
  113.  
  114. /* the end */
  115.  
  116. exit
  117.